#include <stdio.h> 
#include <stdint.h> 

int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) {
    int64_t b = -1, j = 0;
    while (j < num_buckets) {
        b = j;
        key = key * 2862933555777941757ULL + 1;
        j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1));
    }
    return b;
}

int hash(uint64_t obj_id, int node_count) {
    if (node_count <= 0)
        return -1;

    int count = 0;
    do {
        int64_t b = -1, j = 0;
        while (j < node_count) {
            b = j;
            obj_id = obj_id * 2862933555777941757ULL + 1;
            j = (b + 1) * (double(1LL << 31) / double((obj_id >> 33) + 1));
        }

/*        if (count++ < 10)*/
            //printf("key:%lu  bucket:%ld\n", obj_id, b);
        /*else*/
            printf("key:%lu  bucket:%ld\n", obj_id, b);
            return b;

    } while (true);
}

int main(int argc, char **argv) {
    for(int i; i < 100; ++i) {
        printf("---------10----------");
        hash(i, 10);
        printf("---------11----------");
        hash(i, 11);
    }
    return 0;
}
